package controllers;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.model.SelectItem;

import model.entities.ChubMapping;
import myDaos.DirListDao;

@ManagedBean
@ApplicationScoped
public class CountriesManagedBean {
private List<ChubMapping> clist;
private Map<String,String> countryList;
private List<String> allCountries;
private SelectItem[] allCountriesList;

@EJB
private DirListDao dld;

public Map<String, String> getCountryList() {
	return countryList;
}

public void setCountryList(Map<String, String> countryList) {
	this.countryList = countryList;
}

public List<ChubMapping> getClist() {
	return clist;
}

public void setClist(List<ChubMapping> clist) {
	this.clist = clist;
}

public List<String> getAllCountries() {
	return allCountries;
}

public void setAllCountries(List<String> allCountries) {
	this.allCountries = allCountries;
}

public SelectItem[] getAllCountriesList() {
	return allCountriesList;
}

public void setAllCountriesList(SelectItem[] allCountriesList) {
	this.allCountriesList = allCountriesList;
}

@PostConstruct
public void init(){
	//clist = dld.getCountriesList();
	countryList = new HashMap<String, String>();
	for(int i = 0; i < clist.size(); i++) {  
    	countryList.put(clist.get(i).getMapRegion(), clist.get(i).getMapCountry());  
    } 
	allCountries = (List<String>)countryList.values();
	allCountriesList[0] = new SelectItem("", "All");  
    for(int i = 0; i < allCountries.size(); i++) {  
    	allCountriesList[i + 1] = new SelectItem(allCountries.get(i), allCountries.get(i));  
    } 
}

}
